home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / fdimg / oh!.2hd / OH!DEN_B.LZH / TOOLS / CDC / ZCDCSRC.LZH / CDCBGM.C < prev    next >
Text File  |  1995-03-20  |  5KB  |  291 lines

  1. #include    <TNB.H>
  2.  
  3. struct    CDC_TRACK_PTR    {
  4.     short    CDIN;        // 0;NoCD 1;SetCD
  5.     int    CDCMAX;        // CDCの最大記憶数(以下,記憶数)
  6.     int    TRKMAX;        // CDの曲数
  7.     int    ALLTIM;        // CDの全演奏時間
  8.     int    LISTFLAG;    // CDCLISTにあったか -1ならあった
  9.     char    CDNAME[40];        //     CD名        40-1文字
  10.     UNchar    EACHTRKDATA;    // (記憶数)*40    各曲の名前    40-1文字
  11.                 // (記憶数)*4    各曲の演奏時間+拡張曲名flag
  12.                 // (記憶数)*4    各曲のスタート時間
  13. };
  14.  
  15. void    main(ar,av)
  16. int    ar;
  17. char    **av;
  18. {
  19. int    i,j,c,m,n,f;
  20. UNchar    *s;
  21. if ( ar==1 ){
  22.     B_PRINT(
  23.         "CDCBGM with CDC.x BGMモード演奏 Version 0.00 1995 TNB製作所 \r\n"
  24.         "\r\n"
  25.         "使用法:CDCBGM.x [file]|[T]|[[T/][AA:AA:AA][-[BB:BB:BB][,[CC:CC:CC][-[DD:DD:DD]]]]]\r\n"
  26.         "\r\n"
  27.         " T                : T 曲目をBGMにします。\r\n"
  28.         " T/AA:AA:AA-BB:BB:BB        : T 曲目の、AA分AA秒AA~BB分BB秒BBをBGMにします。\r\n"
  29.         " T/AA:AA:AA-BB:BB:BB,CC:CC:CC    : T 曲目の、AA分AA秒AA~BB分BB秒BBを演奏後、\r\n"
  30.         "                     CC分CC秒CC~BB分BB秒BBをBGMにします。\r\n"
  31.         " T/AA:AA:AA-BB:BB:BB,CC:CC:CC-DD:DD:DD\r\n"
  32.         "                : T 曲目の、AA分AA秒AA~BB分BB秒BBを演奏後、\r\n"
  33.         "                     CC分CC秒CC~DD分DD秒DDをBGMにします。\r\n"
  34.         "\r\n"
  35.         "     file            : ZCDC用の ZMSファイルかZMDファイル\r\n"
  36.         "\r\n"
  37.     );
  38.     return;
  39. }
  40. f=OPEN(av[1],0);
  41. if ( f<0 ){
  42.     Disp(av[1]);
  43.     C_INKEY(0x52);
  44.     return;
  45. }
  46. for(;;){
  47.     s=Fgets(f);
  48.     if ( s<=0 )
  49.         break;
  50.     for(;;){
  51.         c=*s++;
  52.         if ( c==0 ) break;
  53.         if ( (c>=0x80 && c<=0x9f) || c>=0xE0 ){
  54.             s++;
  55.             continue;
  56.         }
  57.         if ( c=='C' && s[0]=='D' && (s[1]=='R'||s[1]=='C') && s[3]=='{' && s[4]=='[' ){
  58.             Disp(s+5);
  59.             C_INKEY(0x52);
  60.             break;
  61.         }
  62.     }
  63. }
  64. CLOSE(f);
  65. }
  66.  
  67. /*+++++++++++++++++++++++++++++++++++++++*/
  68. int    Disp(s)
  69. UNchar    *s;
  70. {
  71. int    i,j,aaa[4],ttt,mo,m,n;
  72. struct    CDC_TRACK_PTR *TP;
  73. char    *ss;
  74. UNint    *tl;
  75.  
  76. for(;*s==9||*s==' ';s++);
  77. ss=s;
  78. i=c_atoi(s,&j); s+=j;
  79. for(;*s==9||*s==' ';s++);
  80. ttt=0;
  81. if ( *s=='/' ){
  82.     s++;
  83.     /*トラック単位*/
  84.     TP=C_TRACKS();
  85.     if ( i<1 || i>TP->TRKMAX )
  86.         return(0);
  87.     tl=(&(TP->EACHTRKDATA))+(TP->CDCMAX*40)+(TP->CDCMAX*4);
  88.     ttt=tl[i]&0xFFFFFF;
  89. } elif ( *s==']' || *s==0 ){
  90.     /*BGMモード*/
  91.     C_BGM(i,0,0,0);
  92.     return(1);
  93. } else {
  94.     s=ss;
  95. }
  96. for(;*s==9||*s==' ';s++);
  97. for(m=0;m<4;aaa[m++]=0);
  98. for(m=0;m<4;m++){
  99.     if ( *s==']' || *s==0 ) break;
  100.     if ( *s=='-' || *s==',' ){
  101.         s++;
  102.         if ( m==0 ) aaa[m]=ttt;
  103.     } else {
  104.         i=(s[0]-'0')*0x10000 *10+
  105.           (s[1]-'0')*0x10000    +
  106.           (s[3]-'0')*0x100   *10+
  107.           (s[4]-'0')*0x100    +
  108.           (s[6]-'0')         *10+
  109.           (s[7]-'0');
  110.         s+=8;
  111.         aaa[m]=addtime( i,ttt );
  112.         for(;*s==9||*s==' ';s++);
  113.         if ( *s==']' || *s==0 ) break;
  114.         s++;
  115.     }
  116.     for(;*s==9||*s==' ';s++);
  117. }
  118. /*BGMモード*/
  119. C_BGM(aaa[0],aaa[1],aaa[2],aaa[3]);
  120. return(1);
  121. }
  122. /*************************************
  123.     時間 bcd 同志の足し算  t1+t2
  124. **************************************/
  125. int addtime( int t1,int t2 )
  126. {
  127. /*    00:mm:ss:xx 何分何秒何1/75秒    */
  128. int    t1m,t1s,t1u;
  129. int    t2m,t2s,t2u;
  130. t1m=(t1>>16) & 0xff;
  131. t1s=(t1>>8 ) & 0xff;
  132. t1u=(t1    ) & 0xff;
  133.  
  134. t2m=(t2>>16) & 0xff;
  135. t2s=(t2>>8 ) & 0xff;
  136. t2u=(t2    ) & 0xff;
  137.  
  138. if ( (t1u+=t2u)>=75 ){
  139.     t1u-=75;
  140.     t1s++;
  141. }
  142. if ( (t1s+=t2s)>=60 ){
  143.     t1s-=60;
  144.     t1m++;
  145. }
  146. t1m+=t2m;
  147. return( (t1m<<16)|(t1s<<8)|t1u );
  148. }
  149. /*++++++++++*/
  150. int    c_atoi(m,n)
  151. UNchar    *m;
  152. int    *n;
  153. {
  154. int    i=0,j=0;
  155. UNchar    c;
  156. for(;;){
  157.     if ( *m<'0' || *m>'9' )
  158.         break;
  159.     i=i*10+*m-'0';
  160.     m++;
  161.     j++;
  162. }
  163. if ( n!=0 )    *n=j;        /*うごいたかず!!*/
  164. return(i);
  165. }
  166. /*++++++++++*/
  167. asm("
  168.  
  169. DOS    macro    callname
  170.     dc.w    callname
  171.     endm
  172. _SEEK        equ    $ff42
  173. _READ        equ    $ff3f
  174.  
  175.     .globl    _Fgets
  176. _Fgets:    *------------------------------------------
  177.     *    ファイルから1行をバッファに読み込み
  178.     *    Fgets(f)
  179.  
  180.     movea.l    4(sp),a2
  181.     move.w    #1,-(sp)
  182.     move.l    #0,-(sp)
  183.     move.w    a2,-(sp)
  184.     DOS    _SEEK
  185.     addq.l    #8,sp
  186.     tst.l    d0
  187.     bpl    @f
  188.     moveq    #-1,d0    *えらー
  189.     rts
  190. @@:
  191.     move.l    d0,d2        *シークポインタ
  192.     move.l    #256,-(sp)
  193.     pea    FgetsPTR(pc)
  194.     move.w    a2,-(sp)
  195.     DOS    _READ
  196.     lea    10(sp),sp
  197.     tst.l    d0
  198.     bpl    @f
  199.     moveq    #-1,d0    *エラー
  200.     rts
  201. @@:
  202.     bne    @f
  203.     moveq    #0,d0    *0;終了
  204.     rts
  205. @@:
  206.     lea    FgetsPTR(pc),a1
  207.     moveq    #0,d1
  208. _fgL2:
  209.     move.b    (a1)+,d0
  210.     beq    _fgL3
  211.     cmpi.b    #$0d,d0
  212.     beq    _fgL1_
  213.     cmpi.b    #$0a,d0
  214.     beq    _fgL1
  215.  
  216.     cmpi.b    #$80,d0        *全角
  217.     bcs    @f
  218.     cmpi.b    #$9F+1,d0
  219.     bcs    _fgL4
  220. @@:    cmpi.b    #$E0,d0
  221.     bcc    _fgL4
  222.  
  223.     addq.w    #1,d1
  224.     cmpi.w    #256,d1
  225.     bcc    _fgL3
  226.     bra    _fgL2
  227. _fgL4:
  228.     move.b    (a1)+,d0
  229.     addq.w    #2,d1
  230.     cmpi.w    #256,d1
  231.     bcc    _fgL3
  232.     bra    _fgL2
  233.  
  234. _fgL3:
  235.     clr.b    (a1)
  236.     move.l    #FgetsPTR,d0
  237.     rts
  238. _fgL1_:
  239.     addq.w    #1,d1
  240. _fgL1:
  241.     addq.w    #1,d1
  242.     move.b    #0,-1(a1)
  243.  
  244.     move.w    #0,-(sp)
  245.     move.l    d2,-(sp)
  246.     move.w    a2,-(sp)
  247.     DOS    _SEEK
  248.     move.w    #1,-(sp)
  249.     move.l    d1,-(sp)
  250.     move.w    a2,-(sp)
  251.     DOS    _SEEK
  252.     lea    16(sp),sp
  253.     move.l    #FgetsPTR,d0
  254.     rts
  255.  
  256. FgetsPTR:
  257.     .ds.b    256        * 読み込み用バッファ
  258.     .dc.w    0
  259.     .even
  260.  
  261.  
  262.     .include    CDC.MAC
  263. _C_BGM:
  264.     movem.l    d3-d4,-(sp)
  265.     move.l     4+8(sp),d1
  266.     move.l     8+8(sp),d2
  267.     move.l    12+8(sp),d3
  268.     move.l    16+8(sp),d4
  269.     CDC    _CDC_BGM
  270.     movem.l    (sp)+,d3-d4
  271.     rts
  272. _C_PLAY:
  273.     move.l     4(sp),d1
  274.     move.l     8(sp),d2
  275.     CDC    _CDC_PLAY
  276.     rts
  277. _C_STOP:
  278.     CDC    _CDC_STOP
  279.     rts
  280. _C_INKEY:
  281.     move.l     4(sp),d1
  282.     CDC    _CDC_INKEY
  283.     rts
  284.  
  285. _C_TRACKS:
  286.     CDC    _CDC_TRACKS
  287.     rts
  288. ");
  289.  
  290.  
  291.